package com.oneonefive.trainticketsystem.controller;

import com.oneonefive.trainticketsystem.pojo.Ticket;
import com.oneonefive.trainticketsystem.service.TicketService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class TicketController {
    final
    TicketService ticketService;

    public TicketController(TicketService ticketService) {
        this.ticketService = ticketService;
    }

    @RequestMapping("/insertTic")
    public boolean insertTic(int ticketId, int trainId, String coachNo, String seatNo, Integer sold) {
        return ticketService.insertTic(ticketId, trainId, coachNo, seatNo, sold);
    }

    @RequestMapping("/ticSale")
    public boolean ticSales(Integer ticketId, Integer userId) {
        return ticketService.soldTic(ticketId, userId);
    }

    @RequestMapping("/ticRef")
    public boolean ticRef(Integer ticketId, Integer userId) {
        return ticketService.refundTic(ticketId, userId);
    }

    @RequestMapping("/selectAllTic")
    public List<Ticket> selectTicByTrain(Integer ticketId, Integer trainId, String coachNo, String seatNo, Integer sold, Integer page) {
        return ticketService.selectTicByTrainId(ticketId, trainId, coachNo, seatNo, sold, page);
    }

    @RequestMapping("/deleteByTicId")
    public boolean deleteByTicId(Integer ticketId) {
        return ticketService.removeById(ticketId);
    }

    @RequestMapping("/getTicRowCount")
    public int getTicRowCount(Integer ticketId, Integer trainId, String coachNo, String seatNo, Integer sold) {
        return ticketService.getTicRowCount(ticketId, trainId, coachNo, seatNo, sold);
    }
}
